﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;

/// <summary>
/// Summary description for ToaThuoc
/// </summary>
public class Thuoc
{

    #region local variable declaring
    private int _nErrorCode = -1;//that mean OK;

    string _sMaphieu;
    string _sMaPhieuKham_Cu;

    int _nDoiTuong = 1;
    bool _bCheckBaoHiem = true;
    const char SEPERATE_SYMBOL = '|';

    //use in tach toa thuoc theo khoa
    string _dbname_Static;
    string _sLoaiKham;

    int _nThuocID;
    string _sDbName;
    string _sTenThuoc;
    int _nSoLuong;
    string _sDonVi;
    string _sCachDung;
    string _nLanDung;
    string _nLuongDung;
    string _sDonViDung;
    string _sGhiChu;
    string _sThanhPhan;
    double _dDonGia;

    string _sThuocID_s;
    string _sDbName_s;
    string _sTenThuoc_s;
    string _sSoLuong_s;
    string _sDonVi_s;
    string _sCachDung_s;
    string _sLanDung_s;
    string _sLuongDung_s;
    string _sDonViDung_s;
    string _sGhiChu_s;
    string _sDonGia_s;
    #endregion

    #region Properties
    public int ErrorCode { get { return _nErrorCode; } }
    public string MaPhieu
    {
        get { return _sMaphieu; }
        set { _sMaphieu = value; }
    }

    public string MaPhieuKham_Cu
    {

        set { _sMaPhieuKham_Cu = value; }
    }

    public int DoiTuong
    {
        get { return _nDoiTuong; }
        set { _nDoiTuong = value; }
    }

    public bool CheckThuocBaoHiem
    {
        set { _bCheckBaoHiem = value; }
    }

    public string DBName_Static
    {
        set { _dbname_Static = value; }
    }
    public string LoaiKham
    {
        set { _sLoaiKham = value; }
    }

    public string ThanhPhan
    {
        get { return _sThanhPhan; }
        set { _sThanhPhan = value; }
    }

    //thuoc id
    public int ThuocID
    {
        get { return _nThuocID; }
        set
        {
            _nThuocID = value;
            //_sThuocID_s += _nThuocID.ToString().Trim() + SEPERATE_SYMBOL;
        }
    }
    //DBName
    public string DBname
    {
        get { return _sDbName; }
        set
        {
            _sDbName = value;
            //_sDbName_s += _sDbName.Trim() + SEPERATE_SYMBOL;
        }
    }

    //So luong
    public int SoLuong
    {
        get { return _nSoLuong; }
        set
        {
            _nSoLuong = value;
            //_sSoLuong_s += _nSoLuong.ToString().Trim() + SEPERATE_SYMBOL;
        }
    }
    //Don vi
    public string DonVi
    {
        get { return _sDonVi; }
        set
        {
            _sDonVi = value;
            //_sDonVi_s += _sDonVi.Trim() + SEPERATE_SYMBOL;
        }
    }
    //Cach dung
    public string CachDung
    {
        get { return _sCachDung; }
        set
        {
            _sCachDung = value;
            //_sCachDung_s += _sCachDung.Trim() + SEPERATE_SYMBOL;
        }
    }
    //Lan dung
    public string LanDung
    {
        get { return _nLanDung; }
        set
        {
            _nLanDung = value;
            //_sLanDung_s += _nLanDung.ToString().Trim() + SEPERATE_SYMBOL;
        }
    }
    //Luong dung
    public string LuongDung
    {
        get { return _nLuongDung; }
        set
        {
            _nLuongDung = value;
           // _sLuongDung_s += _nLuongDung.ToString().Trim() + SEPERATE_SYMBOL;
        }
    }
    //Don vi dung
    public string DonViDung
    {
        get { return _sDonViDung; }
        set
        {
            _sDonViDung = value;
            //_sDonViDung_s += _sDonViDung.Trim() + SEPERATE_SYMBOL;
        }
    }
    //Ghi chus
    public string GhiChu
    {
        get { return _sGhiChu; }
        set
        {
            _sGhiChu = value;
           // _sGhiChu_s += _sGhiChu.Trim() + SEPERATE_SYMBOL;
        }
    }

    public string TenThuoc
    {
        get { return _sTenThuoc; }
        set
        {
            _sTenThuoc = value;
            //_sTenThuoc += _sTenThuoc.ToString().Trim() + SEPERATE_SYMBOL;
        }
    }

    #endregion

    private DAL_DonThuoc dal_DonThuoc;
    private DAL_Thuoc dal_Thuoc;
	public Thuoc()
	{
        dal_DonThuoc = new DAL_DonThuoc();
        dal_Thuoc = new DAL_Thuoc();
	}

    public Thuoc(string sMaPhieu, int nDoiTuong, bool bCheckBaoHiem)
    {
        dal_DonThuoc = new DAL_DonThuoc();
        _sMaphieu = sMaPhieu;

        _nDoiTuong = nDoiTuong;
        _bCheckBaoHiem = bCheckBaoHiem;

        _sThuocID_s = "";
        _sDbName_s = "";

        _sSoLuong_s = "";
        _sDonVi_s = "";
        _sCachDung_s = "";
        _sLanDung_s = "";
        _sLuongDung_s = "";
        _sDonViDung_s = "";
        _sGhiChu_s = "";
    }

    public List<Thuoc> LayDonThuocTheoPhieuKham(string MaPhieu)
    {
        DataTable dt = dal_DonThuoc.LayToaThuocTheoPhieuKham(MaPhieu);
        List<Thuoc> lst = new List<Thuoc>();
        Thuoc newThuoc = new Thuoc();
        foreach(DataRow row in dt.Rows)
        {
            newThuoc.TenThuoc = Factory.emptyNull(row["TenThuoc"]);
            newThuoc.SoLuong = int.Parse(Factory.emptyNull(row["SoLuong"]));
            newThuoc.DonVi = Factory.emptyNull(row["DonVi"]);
            newThuoc.LuongDung = Factory.emptyNull(row["SoLuongDung"]);
            newThuoc.GhiChu = Factory.emptyNull(row["GhiChu"]);
            newThuoc.ThanhPhan = Factory.emptyNull(row["ThanhPhan"]);
            newThuoc.CachDung = Factory.emptyNull(row["CachDung"]);
            newThuoc.LanDung = Factory.emptyNull(row["SoLan"]);
            lst.Add(newThuoc);
        }
        return lst;
    }

    public List<string> LayCachDungThuoc()
    {
        List<string> CDThuoc = new List<string>();
        DataTable dt = dal_Thuoc.LayCachDungThuoc();
        foreach(DataRow row in dt.Rows)
        {
            CDThuoc.Add(Factory.emptyNull(row["CachDung"]));
        }
        return CDThuoc;
    }

    public List<string> LayDonViDungThuoc()
    {
        List<string> DVThuoc = new List<string>();
        DataTable dt = dal_Thuoc.LayDanhMucDonViDung();
        foreach (DataRow row in dt.Rows)
        {
            DVThuoc.Add(Factory.emptyNull(row["DonVi"]));
        }
        return DVThuoc;
    }
}